# Contributor: Magnus Sandin <magnus.sandin@gmail.com>
# Maintainer: Magnus Sandin <magnus.sandin@gmail.com>
pkgname=lsp-plugins
pkgver=1.2.19
pkgrel=0
pkgdesc="Collection of free plugins compatible with LADSPA, LV2 and LinuxVST"
url="https://lsp-plug.in"
# loongarch64: make fetch fails on the builder
arch="all !loongarch64"
license="LGPL-3.0-or-later"
install="$pkgname.post-upgrade"
makedepends="
	cairo-dev
	cmd:php
	cmd:git
	gst-plugins-base-dev
	jack-dev
	ladspa-dev
	libsndfile-dev
	libxrandr-dev
	lv2-dev
	mesa-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-dev
	liblsp-r3d-glx-lib
	$pkgname-xdg::noarch
	$pkgname-clap
	$pkgname-ladspa
	$pkgname-lv2
	$pkgname-vst2
	"
source="
	lsp-plugins-$pkgver.tar.gz::https://github.com/lsp-plugins/lsp-plugins/archive/refs/tags/$pkgver.tar.gz
	musl-locale.post_download_patch
	"
options="!check" # no testsuite

# GitLab CI and builders run armhf/armv7 as 32-bit arches on aarch64. Thus, we
# cannot rely on the uname -m output on these platforms, as the build system is
# broken and does not use the gcc default architecture, rather passing -march
# values manually.
case "$CARCH" in
armhf) export ARCHITECTURE=armv6l ;;
armv7) export ARCHITECTURE=armv7l ;;
esac

build() {
	export CFLAGS="$CFLAGS -O2 -flto=auto"
	export CXXFLAGS="$CXXFLAGS -O2 -flto=auto"
	make clean
	make \
		PREFIX=/usr \
		ADD_FEATURES=xdg \
		ARTIFACT_EXPORT_HEADERS=1 \
		config
	make fetch

	# Patch fetched locale file
	patch -p1 < ../../musl-locale.post_download_patch

	make
}

package() {
	make DESTDIR="$pkgdir" install
	rm "$pkgdir"/usr/lib/*.a
}

lib() {
	pkgdesc="$pkgdesc (lsp-plugins gfx library)"

	amove usr/lib/liblsp-r3d-glx-lib*
}

xdg() {
	pkgdesc="$pkgdesc (XDG integration)"

	amove usr/share/applications
	amove usr/share/desktop-directories
	amove usr/share/icons
	amove etc/xdg/menus/applications-merged
}

clap() {
	pkgdesc="$pkgdesc (clap integration)"
	depends="liblsp-r3d-glx-lib=$pkgver-r$pkgrel"

	amove usr/lib/clap
}

ladspa() {
	pkgdesc="$pkgdesc (ladspa integration)"
	depends="liblsp-r3d-glx-lib=$pkgver-r$pkgrel"

	amove usr/lib/ladspa
}

lv2() {
	pkgdesc="$pkgdesc (lv2 plugins)"
	depends="liblsp-r3d-glx-lib=$pkgver-r$pkgrel"

	amove usr/lib/lv2
}

vst2() {
	pkgdesc="$pkgdesc (vst2 plugins)"
	depends="liblsp-r3d-glx-lib=$pkgver-r$pkgrel"

	amove usr/lib/vst
}

sha512sums="
68c768af02edd96bc6edeec84212454672deda130303a92770f4af2d1b5bda89d14b2a6ffe5e3bc965a776f329bd4ca1a0fedf2fa84c5b3c6ef1c83b20873684  lsp-plugins-1.2.19.tar.gz
4ea66a747f7d5d80840e540e8e8509efd92001f7e9265ccaa0e829eb2dd1af180a73161c707b100e1368697774714179b4c1fc638a4166ef13e454e537d2dbf2  musl-locale.post_download_patch
"
